<template>
  <div class='card first-box'>
    <Scroll :hasmore="hasmore" :pullup="pullup">
      <List :data="listData" :toSendUrl="url"></List>
    </Scroll>
  </div>
</template>
<script>
import Scroll from '../../common/scroller'
import List from '../../members/voucher/common/list'
export default {
  components: {Scroll,List},
  name: "",
  data() {
    return {
      hasmore:false,
      pageInfo:{
        page:1
      },
      listData:[
        // {
        //   title:"免费洗车",
        //   money:38,//
        //   time:"2018-12-12",
        //   over:"5",//超出多少可以使用
        //   state:0,//0未使用,1已使用，-1过期
        //   id:"1",//卡券id
        // }
      ],
      url:"/works/card/send",//卡券派发地址
    };
  },
  methods: {

    // 下拉刷新方法回调
    pullup(func){
      if(this.hasmore){
        this.pageInfo.page++
         _g.orderList([this.getList,func])
         return
      }
    },
    getList(){
      var params={
        currPageNo:this.pageInfo.page
      }
      _g.apiPost("couponApp/getEmployeeCoupon.do",params).then(res=>{
        if(res.msg){
          var that=this
          this.$store.state.dialogs.alert.content=res.msg
          this.$store.state.dialogs.alert.show=true
          this.$store.state.dialogs.alert.OK=function(){
            that.$router.go(-1)
          }
        }else{
          this.hasmore=res.data.hasNextPage

          var goal = []
          res.data.list.forEach(ele => {
            goal.push({
              title:ele.couponName,
              money:ele.couponValue,
              time:ele.validTill?_g.formatTime(ele.validTill):"",
              over:ele.consumptionFull,
              state:ele.couponType,
              id:ele.id,
            })
          });

          this.$set(this,"listData",this.listData.concat(goal))
        }

      })
    }
  },
  created() {
    this.getList()
  }
};
</script>
<style lang="scss" scoped>
.card {
}
</style>